package com.hsmpay.mobile.action.added.of;

import com.hsmpay.mobile.action.added.AddedBaseAction;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

//import zyzf.added.of.Ofpay;
//import zyzf.pay.qian4.utils.DesUtil;
//import zyzf.pay.qian4.utils.Qian48Constant;

/**
 * @author 欧飞 接口
 */
@Controller("ofPayRechargeAction")
@Scope("prototype")
public class OfPayRechargeAction extends AddedBaseAction {
    private static final long serialVersionUID = 8625337024040059917L;
//	private static Logger log = Logger.getLogger(OfPayRechargeAction.class);
//	static Ofpay ofpay = new Ofpay();
//	private String mobile;
//	HashMap<String, Object> resMap = new HashMap<String, Object>();
//	
//	private String recharge_ret_url =  Constant.getAttribute("SYSTEM_Mobile_BASE_URL")+"/ofPayRecharge/fixtelRollback.action"; //话费充值回调
//	private String guhua_recharge_ret_url = Constant.getAttribute("SYSTEM_Mobile_BASE_URL")+"/ofPayRecharge/onlinetelorder.action"; //固话/宽带充值回调
//	private String teltype;//运营商 
//	private String chargeType;//充值类型
//	private String faceValue;//面值
//	
//	
//	
//	private Long guhua_orderTypeId = 66L;//固话充值
//	private Long kuandai_orderTypeId = 67L;//宽带充值
//	
//	
//	/**
//	 * 手机号码归属地查询
//	 * 1868869|广东东莞|联通
//	 * @throws Exception 
//	 */
//	public void mobileInfo() throws Exception{
//		mobile = getJsonString("mobile");
//		if(StringUtils.isEmpty(mobile)){
//			log.info("手机号码归属地查询时, 传入参数mobile为空");
//			sendAppErrorMsg("6001", "mobile");
//			return ;
//		}
//		
//		String result = ofpay.mobinfo(mobile);
//		String[] resArray = result.split(",");
//		resMap.clear();
//		resMap.put("reqCode", "0000");
//		resMap.put("reqMsg", "手机号码归属地请求成功！");
//		resMap.put("attribution", resArray[1]);
//		resMap.put("company", resArray[2]);
//		sendAppMsg(result);
//	}
//	
//	/**
//	 * 检查手机是否可以充值
//	 * 1#成功#0000&江苏南京
//	 * @throws Exception
//	 */
//	public void telcheck()throws Exception{
//		mobile = getJsonString("mobile");
//		faceValue = getJsonString("faceValue");
//		amount = getJsonString("amount");
//		
//		if(StringUtils.isEmpty(mobile)){
//			log.info("检查手机是否可以充值时, 传入参数mobile为空");
//			sendAppErrorMsg("6001", "mobile");
//			return ;
//		}
//		if(StringUtils.isEmpty(faceValue)){
//			log.info("检查手机是否可以充值时, 传入参数faceValue为空");
//			sendAppErrorMsg("6001", "faceValue");
//			return ;
//		}
//		if(StringUtils.isEmpty(amount)){
//			log.info("检查手机是否可以充值时, 传入参数amount为空");
//			sendAppErrorMsg("6001", "amount");
//			return ;
//		}
//	
//		try{
//			//判断 欧飞余额
//			Double price = Double.parseDouble(amount)/100;
//			Double balance = ofpay.getBalance();
//			if(price > balance){
//				String message = encryptAppMsg(0,"OF99","该面值正在维护，请稍候再试！");
//				sendAppMsg(message);
//				return ;
//			}
//			
//			functionKey = "PHONERECHARGE";
//			if(!checkPIV(functionKey)){
//				log.warn("检查手机是否可以充值时, 接口暂停使用！");
//				return;
//			}
//			
//			//Integer price = Integer.parseInt(amount)/100;
//			String result = ofpay.telcheck(mobile,faceValue,Ofpay.userid);
//			String[] resArray = result.split("#");
//			resMap.clear();
//			resMap.put("reqCode", "0000");
//			resMap.put("reqMsg", "检查手机是否可以充值请求成功！");
//			resMap.put("status", resArray[0]);
//			resMap.put("errorMsg", resArray[1]);
//			if(resArray.length > 2)
//				resMap.put("other", resArray[2]);
//			sendAppMsg(resMap);
//		}catch(Exception e){
//			e.printStackTrace();
//			throw e;
//		}
//	}
//	
//	/**
//	 * 话费充值
//	 * @throws Exception
//	 */
//	public void onlinetelorder()throws Exception{
//		terminalTypeId = Long.parseLong(getJsonString("terminalTypeId"));
//		roleId = Long.parseLong(getJsonString("roleId"));
//		userId = Long.parseLong(getJsonString("userId"));
//		clientType = Integer.parseInt(getJsonString("clientType"));
//		mobile = getJsonString("mobile");
//		faceValue = getJsonString("faceValue");
//		amount = getJsonString("amount");
////		merchantOrderId = getJsonString("merchantOrderId");
//		merchantOrderTime = getJsonString("merchantOrderTime");
//		accountNumber = getJsonString("accountNumber");
//		pin = getJsonString("pin");
//		track2Data = getJsonString("track2Data");
//		track3Data = getJsonString("track3Data");
//		signaturePath = getJsonString("signaturePath");
//		encryType = getJsonString("encryType");
//		icCardYu = getJsonString("icCardYu");//IC卡 域
//		transTerminalId = getJsonString("transTerminalId");
//		
//		if(StringUtils.isEmpty(mobile)){
//			log.info("话费充值时, 传入参数mobile为空");
//			sendAppErrorMsg("6001", "mobile");
//			return ;
//		}
//		if(StringUtils.isEmpty(faceValue)){
//			log.info("话费充值时, 传入参数faceValue为空");
//			sendAppErrorMsg("6001", "faceValue");
//			return ;
//		}
//		if(StringUtils.isEmpty(amount)){
//			log.info("话费充值时, 传入参数amount为空");
//			sendAppErrorMsg("6001", "amount");
//			return ;
//		}
//		
//		try{
//			Double price = Double.parseDouble(amount)/100;
//			if(price < 0){
//				log.warn("话费充值时, 金额暂时不能小于0！");
//				sendAppErrorMsg("6002");
//				return;
//			}
//			
////			if(price < 50){
////				log.warn("话费充值时, 金额暂时不能小于50！");
////				sendAppErrorMsg("6002");
////				return;
////			}
//			
//			//判断 欧飞余额
//			Double balance = ofpay.getBalance();
//			if(price > balance){
//				String message = encryptAppMsg(0,"OF99","该面值正在维护，请稍候再试！");
//				sendAppMsg(message);
//				return ;
//			}
//			
//			
//			functionKey = "PHONERECHARGE";
//			if(!checkPIV(functionKey)){
//				log.warn("话费充值时, 接口暂停使用！");
//				return;
//			}
//			
//			//屏蔽伪卡
//			if(transRefuseCardService.isRefuseCard(accountNumber)){
//				sendAppErrorMsg("6073", accountNumber);
//				return;
//			}
//			
//			Long tchannelId =  (Long) getRequest().getAttribute("tchannelId");
//			Long payTchannel =  (Long) getRequest().getAttribute("payTchannel");
//			getRequest().removeAttribute("tchannelId");
//			getRequest().removeAttribute("payTchannel");
//			//IC卡
////			if(StringUtils.isNotEmpty(icCardYu)){
////				payTchannel = new Long(PurchaseBaseAction.TC_anxinybSocket);
////			}
//			if("1".equals(encryType)){
//				track2Data = ME30DataDecode.decryptTrace2(track2Data);
//				//icCardYu.replace(oldChar, newChar)
//			}else if("2".equals(encryType)){
//				String trackOData = getJsonString("trackOData");
//				String[] trackA = ME30DataDecode.decryptTrace2_aic(trackOData, track2Data);
//				track2Data = trackA[0];
//				track3Data = trackA[1];
//			}
//			track2Data = track2Data.replaceAll("F", "");//屏蔽二磁道有F的情况
//			
//			Date date = new Date();
//			merchantOrderTime = DateConvertUtil.dateString(date,"yyyyMMddHHmmss");
//			String orderNum = getOrderNumByDate(date);
//			User user = userService.getUserById(userId);
//			if(null != user){
//				String dynamicKeyData= DesUtil.generate16Key();
////				String transType = "100000";
////				pin=DesUtil.encryptPin(merchantOrderTime, pin, Qian48Constant.pinKey);
////				track2Data=DesUtil.encryptStanderTranck(merchantOrderTime, dynamicKeyData, Qian48Constant.DesKey, track2Data);
////				byte[] desKey = DesUtil.compute3DES(DesUtil.hexStringToByte(Qian48Constant.macKey),DesUtil.hexStringToByte(merchantOrderTime + "80"));
////				String orgMacStr = accountNumber + " " + pin + " " + track2Data + " " + orderNum + " " + amount + " " + merchantOrderTime + " " +  transType;
////				//报文鉴别码
////				String mac=DesUtil.mac(DesUtil.byte2hex(desKey), orgMacStr);
//				//组装 发送数据 
//				Qian4SendLog send = new Qian4SendLog();
//				send.setCallType(0);
//				send.setUserId(userId);
//				send.setOrderTypeId(RechargeFCAction.recharge_orderTypeId);
//				send.setApplication("Purchase.Req");
//				send.setTransType("100000");//
//				send.setSendTime(date);
//				send.setSendSeqId(TimeUtils.getTimeToString());
//				send.setMerchantId(Qian48Constant.merchantId);//商户代码 ##
//				send.setTerminalId(Qian48Constant.jianyi_terminalId);
//				send.setPlatformId(Qian48Constant.platformId);
//				
//				send.setMerchantOrderId(orderNum);//商户订单号
//				send.setMerchantOrderTime(DateConvertUtil.stringDate(merchantOrderTime,"yyyyMMddHHmmss"));//商户订单号时间
//				send.setTransTime(send.getSendTime());
//				send.setTransAmt(amount);
//				send.setCurrency("156");
//				send.setAccountNumber(accountNumber);
//				send.setPin(pin);
//				send.setTrack2Data(track2Data);
//				send.setTrack3Data(track3Data);
//				//send.setCardholderSign(cardholderSign);//电子签名
//				send.setDynamicKeyData(dynamicKeyData);
////				send.setMac(mac);
//				send.setCollectionType(payTchannel.intValue());
//				send.setIp(URLDecoderTools.getRemoteHost(getRequest()));//IP
//				send.setIcCardYu(icCardYu);
//				send.setCardTypeN(StringUtils.isEmpty(icCardYu) ? 1 : 2);//1 磁条卡 2 IC卡
//				send.setTransTerminalId(transTerminalId);
//				
//				AddedOrder order = new AddedOrder();
//				order.setOrderNum(orderNum);
//				order.setTerminalTypeId(terminalTypeId);
//				order.setRoleId(roleId);
//				order.setClientType(clientType);
//				order.setOrderTypeId(RechargeFCAction.recharge_orderTypeId);
//				order.setUserId(userId);
//				order.setTransMoney(price);
//				order.setBankCard(accountNumber);
//				order.setMobile(mobile);
//				order.setStatus(3);
//				order.setCreateDate(date);
//				order.setLongTime(date.getTime());
//				order.setSignaturePath(signaturePath);
//				order.setChannelId(tchannelId.longValue());
//				Map<String,String> thirdMap = new HashMap<String, String>();
//				thirdMap.put("faceValue", faceValue);//面值
//				order.setThirdData(JSONStringBuilder.getAjaxString(thirdMap));
//				order.setPayTchannel(payTchannel);
//				order.setCardTypeN(send.getCardTypeN());//1 磁条卡 2 IC卡
//				order.setTransTerminalId(transTerminalId);
////				//安心一百 socket 参数
////				Map<String,String> miyao = null;
////				if(payTchannel.intValue() == 15){
////					Tchannel tc = tchannelService.searchMobileTchannelByCode(payTchannel.intValue());
////					miyao = anxinybService.getMiYao(tc.getOtherParam());
////					send.setBankOrderNum(anxinybService.searchAnXinYBTransId().toString());//查询序列 获取动态流水号
////					send.setBatchId(miyao.get("batchId"));//批次号
////					order.setBankOrderNum(send.getBankOrderNum());
////					order.setBatchId(send.getBatchId());
////				}
////				
////				long sendId = addedOrderService.insertOrder(send, order);
////				send.setId(sendId);
////				
////				Map<String,Object> result = new HashMap<String, Object>();
////				//去支付
//////				PurchaseResult rs = hanxinService.purchase(send,0.0040);
////				PurchaseResult rs = null;
////					
////				switch(payTchannel.intValue()){
////					case 15:rs = anxinybPayService.billPayment(send, miyao.get("pinKey"), miyao.get("macKey"));break;
////					case 2:
////					case 4: rs = lianYiJiaService.fdPurchase(send);break;
////					default:rs = hanxinService.purchase(send,0.004);
////				}
//				Map<String,Object> result = new HashMap<String, Object>();
//				PurchaseResult rs = payOrder(send,order);
//				if(0 == rs.getStatus()){//
//					log.debug("支付失败");
//					resMap.clear();
//					resMap.put("reqCode", rs.getReqCode());
//					resMap.put("reqMsg", rs.getReqMsg());
//					//修改订单
//					addedOrderService.receivablesError(order.getId(),0, rs.getReqCode(), rs.getReqMsg());
//					qian4SendLogService.updateResCodeMassage(send.getId(), rs.getReqCode(), rs.getReqMsg());
//				}else{
//					order = addedOrderService.purchaseResolveResult(order,send,rs);
//					qian4SendLogService.updateResCodeMassage(send.getId(), order.getReqCode(), order.getReqMsg());
//					resMap.clear();
//					resMap.put("reqCode", order.getReqCode());
//					resMap.put("reqMsg", order.getReqMsg());
//					if("0000".equals(order.getReqCode())){
//						//String ret_url = recharge_ret_url + "?sporder_id="+orderNum+"&cardnum="+price+"&cardid=140101";
//						result = ofpay.onlineorder(orderNum, merchantOrderTime, "140101", faceValue, mobile, recharge_ret_url);
//						log.debug("充值结果："+result);
//						if("1".equals(result.get("retcode")) && ("1".equals(result.get("status")) || "0".equals(result.get("status")))){
//							int status = 1;
//							if("0".equals(result.get("status"))) status = 2;
//							addedOrderService.updateThirdCodeAndMsg(order.getId(), status, result.get("retcode").toString(), result.get("err_msg")+"", result.get("orderid").toString());
//							resMap.put("reqCode", "0000");
//							resMap.put("reqMsg", "充值成功！");
//							//小票
//							resMap.put("category", orderType.get(order.getOrderTypeId()));
//							resMap.put("status", order.getStatus());
//							resMap.put("orderNum", order.getOrderNum());
//							resMap.put("transTime",  DateConvertUtil.dateString(order.getCreateDate(),"HH:mm:ss"));
//							String cParam = terminalTypeId+"_"+order.getId();
//							String cParamB64 = new String(Base64.encode(cParam.getBytes("UTF-8")),"UTF-8");
//							resMap.put("certificateUrl",Certificate+URLEncoder.encode(cParamB64,"UTF-8"));
//							resMap.put("merchantName", Q4BaseAction.MERCHANT_NAME);//商户名称
//							resMap.put("merchantId", Q4BaseAction.MERCHANT_ID);//商户编号
//							resMap.put("terminalId", send.getTerminalId());//终端编号
//							String acquirersName = user.getOpeningBank();
//							if(null != acquirersName){
//								acquirersName = acquirersName.replace("中国", "");
//							}
//							resMap.put("acquirersName", null != acquirersName ? acquirersName : order.getIssueBank());//收单行
//							resMap.put("issueBank", null == order.getIssueBank() ? "" : order.getIssueBank());//发卡行
//							resMap.put("bankCard", order.getBankCard());//收款卡号
//							resMap.put("cardType", null == order.getCardType()? "" : order.getCardType());//收款卡号
//							resMap.put("expireDate", null == order.getExpireDate() ? "" : order.getExpireDate());//卡有效期（预授权时）
//							resMap.put("batchId", null == order.getBatchId() ? "" : order.getBatchId());//批次号
//							resMap.put("authorizationCode", null == order.getAuthorizationCode() ? "" : order.getAuthorizationCode());//授权码
//							resMap.put("bankTransTime", DateConvertUtil.dateString(order.getCreateDate(),"yyyy/MM/dd"));//日期/时间  transPriorSettle.getBankTransTime()
//							resMap.put("transMoney", order.getTransMoney());//交易金额
//							resMap.put("bankRef", order.getBankRef());//参考号
//							resMap.put("searchId", order.getSearchId());//凭证号
//							resMap.put("transId", order.getBankOrderNum());//银联交易流水号
//							
//							resMap.put("thirdCode", result.get("retcode").toString());//第三方代码
//							resMap.put("thirdMsg", null == result.get("err_msg") ? "" : result.get("err_msg"));//第三方描述
//							resMap.put("thirdOrderNum", null == result.get("orderid") ? "" : result.get("orderid"));//第三方订单号
//						}else{
//							log.debug(result.get("retcode")+"============="+(!"1".equals(result.get("retcode"))));
//							if("1005".equals(result.get("retcode")) ||  !"1".equals(result.get("retcode")) || "9".equals(result.get("status"))){//只用 话费充值的撤销的情况下 我们才能撤销
//								addedOrderService.updateThirdCodeAndMsg(order.getId(), 4, result.get("retcode").toString(), result.get("err_msg")+"", null);
//								//撤销订单
//								revocationOrderTimeOut(send,order.getId());
//							}
//							resMap.clear();
//							resMap.put("reqCode", "0001");
//							resMap.put("reqMsg", "充值失败！");
//							resMap.put("thirdCode", result.get("retcode").toString());//第三方代码
//							resMap.put("thirdMsg", null == result.get("err_msg") ? "" : result.get("err_msg"));//第三方描述
//							resMap.put("thirdOrderNum", null == result.get("orderid") ? "" : result.get("orderid"));//第三方订单号
//							resMap.put("status", 4);
//						}
//					}
//				}
//				
//				//检测 银联返回结果 如果是有违法嫌疑的  那么将暂停该笔结算
//				transRefuseCardService.checkRefuseClear(userId, rs.getReqMsg(), order.getOrderNum(), order.getOrderTypeId());
//				sendAppMsg(resMap);
//			}
//		}catch(Exception e){
//			e.printStackTrace();
//			throw e;
//		}
//	}
//	
//	/**
//	 * 手机充值回调
//	 * /ofPayRecharge/mobileRollback.action?userid=Axxxxx&userpws=xxxxxxx&cardid=140101&cardnum=1&sporder_id=xxxxxxxxx&sporder_time=xxxxxxxx&game_userid=xxxxx&md5_str=xxxxxxxxxxxxx&ret_url=xxxxx&version=6.0
//	 * mobileRollback
//	 * @throws Exception
//	 */
//	public void mobileRollback()throws Exception{
//		log.error("手机充值回调URI：###"+getRequest().getRequestURL()+"###");
//		log.error("请求的所有参数：###"+getRequest().getParameterMap()+"###");
//		String orderNum = (String) getRequest().getParameter("sporder_id");
//		String ordersuccesstime = (String) getRequest().getParameter("ordersuccesstime");
//		Integer ret_code = Integer.parseInt((String) getRequest().getParameter("ret_code"));
//		String desc = (String) getRequest().getParameter("err_msg");
//		
//		log.debug("orderNum "+orderNum);
//		log.debug("ordersuccesstime "+ordersuccesstime);
//		log.debug("ret_code "+ret_code);
//		log.debug("err_msg "+desc);
//		
//		try{
//			AddedOrder order = new AddedOrder();
//			order.setOrderNum(orderNum);
//			order = addedOrderService.searchEntity(order);
//			Integer status = 0;
//			String resCode = "0000";
//			if(1 == ret_code){
//				status  = 1;
//			}else if(9 == ret_code){
//				status  = 4;
//			}
//			resCode = NumberUtil.supplyAll(ret_code, 4);
//			if(null != order){
//				addedOrderService.updateThirdCodeAndMsg(order.getId(), status,resCode , desc, null);
//				
//				if(9 == ret_code){//撤销
//					Qian4SendLog send = qian4SendLogService.getQian4SendLogByMOrderId(order.getOrderNum());
//					revocationOrderTimeOut(send,order.getId());
//				}
//				
//				resMap.clear();
//				resMap.put("reqCode", "0000");
//				resMap.put("reqMsg", "回调成功能！");
//				sendAjaxResponse(resMap);
//			}else{
//				resMap.clear();
//				resMap.put("reqCode", "0099");
//				resMap.put("reqMsg", "回调失败,不存在该订单！！");
//				sendAjaxResponse(resMap);
//			}
//			
//		}catch(Exception e){
//			e.printStackTrace();
//			throw e;
//		}
//	}
//	
//	/**
//	 * 固话/宽带直充查询
//	 * @throws Exception
//	 */
//	public void fixtelquery()throws Exception{
//		mobile = getJsonString("mobile");
//		faceValue = getJsonString("faceValue");
//		teltype = getJsonString("teltype");
//		chargeType = getJsonString("chargeType");
//		amount = getJsonString("amount");
//		
//		if(StringUtils.isEmpty(mobile)){
//			log.info("检查手机是否可以充值时, 传入参数mobile为空");
//			sendAppErrorMsg("6001", "mobile");
//			return ;
//		}
//		if(StringUtils.isEmpty(amount)){
//			log.info("检查手机是否可以充值时, 传入参数amount为空");
//			sendAppErrorMsg("6001", "amount");
//			return ;
//		}
//		if(StringUtils.isEmpty(faceValue)){
//			log.info("检查手机是否可以充值时, 传入参数faceValue为空");
//			sendAppErrorMsg("6001", "faceValue");
//			return ;
//		}
//		if(StringUtils.isEmpty(teltype)){
//			log.info("检查手机是否可以充值时, 传入参数teltype为空");
//			sendAppErrorMsg("6001", "teltype");
//			return ;
//		}
//		if(StringUtils.isEmpty(chargeType)){
//			log.info("检查手机是否可以充值时, 传入参数chargeType为空");
//			sendAppErrorMsg("6001", "chargeType");
//			return ;
//		}
//		try{
//			//判断 欧飞余额
//			Double price = Double.parseDouble(amount)/100;
//			Double balance = ofpay.getBalance();
//			if(price > balance){
//				String message = encryptAppMsg(0,"OF99","该面值正在维护，请稍候再试！");
//				sendAppMsg(message);
//				return ;
//			}
//			functionKey = "FIXED_BROADBAND";
//			if(!checkPIV(functionKey)){
//				log.warn("固话/宽带直充查询时, 接口暂停使用！");
//				return;
//			}
//			
//			Map<String,Object> result = ofpay.fixtelquery(teltype, mobile, faceValue, chargeType);
//			
//			resMap.clear();
//			resMap.put("reqCode", "0000");
//			resMap.put("reqMsg", "请求成功！");
//			resMap.put("status", result.get("retcode"));
//			resMap.put("errorMsg", result.get("err_msg"));
//			resMap.putAll(result);
//			sendAppMsg(resMap);
//		}catch(Exception e){
//			e.printStackTrace();
//			throw e;
//		}
//	}
//	
//	/**
//	 * 固话/宽带直充
//	 * @throws Exception
//	 */
//	public void fixtelorder()throws Exception{
//		
//		terminalTypeId = Long.parseLong(getJsonString("terminalTypeId"));
//		roleId = Long.parseLong(getJsonString("roleId"));
//		userId = Long.parseLong(getJsonString("userId"));
//		clientType = Integer.parseInt(getJsonString("clientType"));
//		mobile = getJsonString("mobile");
//		amount = getJsonString("amount");
//		faceValue = getJsonString("faceValue");
//		teltype = getJsonString("teltype");
//		chargeType = getJsonString("chargeType");
//		encryType = getJsonString("encryType");
//		icCardYu = getJsonString("icCardYu");//IC卡 域
//		transTerminalId = getJsonString("transTerminalId");//翰星终端ID
//		
////		merchantOrderId = getJsonString("merchantOrderId");
//		merchantOrderTime = getJsonString("merchantOrderTime");
//		accountNumber = getJsonString("accountNumber");
//		pin = getJsonString("pin");
//		track2Data = getJsonString("track2Data");
//		track3Data = getJsonString("track3Data");
//		signaturePath = getJsonString("signaturePath");
//		
//		if(StringUtils.isEmpty(mobile)){
//			log.info("固话/宽带直充时, 传入参数mobile为空");
//			sendAppErrorMsg("6001", "mobile");
//			return ;
//		}
//		if(StringUtils.isEmpty(amount)){
//			log.info("固话/宽带直充时, 传入参数amount为空");
//			sendAppErrorMsg("6001", "amount");
//			return ;
//		}
//		if(StringUtils.isEmpty(faceValue)){
//			log.info("固话/宽带直充时, 传入参数faceValue为空");
//			sendAppErrorMsg("6001", "faceValue");
//			return ;
//		}
//		if(StringUtils.isEmpty(teltype)){
//			log.info("固话/宽带直充时, 传入参数teltype为空");
//			sendAppErrorMsg("6001", "teltype");
//			return ;
//		}
//		if(StringUtils.isEmpty(chargeType)){
//			log.info("固话/宽带直充时, 传入参数chargeType为空");
//			sendAppErrorMsg("6001", "chargeType");
//			return ;
//		}
//		try{
//			Double price = Double.parseDouble(amount)/100;
////			if(price < 50){
////				log.warn("话费充值时, 金额暂时不能小于50！");
////				sendAppErrorMsg("6002");
////				return;
////			}
//			//判断 欧飞余额
//			Double balance = ofpay.getBalance();
//			if(price > balance){
//				String message = encryptAppMsg(0,"OF99","该面值正在维护，请稍候再试！");
//				sendAppMsg(message);
//				return ;
//			}
//			functionKey = "FIXED_BROADBAND";
//			if(!checkPIV(functionKey)){
//				log.warn("固话/宽带直充时, 接口暂停使用！");
//				return;
//			}
//			
//			//屏蔽伪卡
//			if(transRefuseCardService.isRefuseCard(accountNumber)){
//				sendAppErrorMsg("6073", accountNumber);
//				return;
//			}
//		
//			if("1".equals(encryType)){
//				track2Data = ME30DataDecode.decryptTrace2(track2Data);
//				//icCardYu.replace(oldChar, newChar)
//			}else if("2".equals(encryType)){
//				String trackOData = getJsonString("trackOData");
//				String[] trackA = ME30DataDecode.decryptTrace2_aic(trackOData, track2Data);
//				track2Data = trackA[0];
//				track3Data = trackA[1];
//			}
//			track2Data = track2Data.replaceAll("F", "");//屏蔽二磁道有F的情况
//			
//			TerminalPrivileges tp = terminalPrivilegesService.searchPrivilegesByFunctionKey(functionKey);
//			
//			
//			Long orderTypeId = guhua_orderTypeId;
//			if("".equals(chargeType))orderTypeId = kuandai_orderTypeId;
//			Date date = new Date();
//			merchantOrderTime = DateConvertUtil.dateString(date,"yyyyMMddHHmmss");
//			String orderNum = getOrderNumByDate(date);
//			User user = userService.getUserById(userId);
//			if(null != user){
////				String dynamicKeyData= DesUtil.generate16Key();
////				String transType = "100000";
////				pin=DesUtil.encryptPin(merchantOrderTime, pin, Qian48Constant.pinKey);
////				track2Data=DesUtil.encryptStanderTranck(merchantOrderTime, dynamicKeyData, Qian48Constant.DesKey, track2Data);
////				byte[] desKey = DesUtil.compute3DES(DesUtil.hexStringToByte(Qian48Constant.macKey),DesUtil.hexStringToByte(merchantOrderTime + "80"));
////				String orgMacStr = accountNumber + " " + pin + " " + track2Data + " " + orderNum + " " + amount + " " + merchantOrderTime + " " +  transType;
////				//报文鉴别码
////				String mac=DesUtil.mac(DesUtil.byte2hex(desKey), orgMacStr);
//				//组装 发送数据 
//				Qian4SendLog send = new Qian4SendLog();
//				send.setCallType(0);
//				send.setUserId(userId);
//				send.setOrderTypeId(orderTypeId);
//				send.setApplication("Purchase.Req");
//				send.setTransType("100000");//
//				send.setSendTime(date);
//				send.setSendSeqId(TimeUtils.getTimeToString());
//				send.setMerchantId(Qian48Constant.merchantId);//商户代码 ##
//				send.setTerminalId(Qian48Constant.jianyi_terminalId);
//				send.setPlatformId(Qian48Constant.platformId);
//				
//				send.setMerchantOrderId(orderNum);//商户订单号
//				send.setMerchantOrderTime(DateConvertUtil.stringDate(merchantOrderTime,"yyyyMMddHHmmss"));//商户订单号时间
//				send.setTransTime(send.getSendTime());
//				send.setTransAmt(amount);
//				send.setCurrency("156");
//				send.setAccountNumber(accountNumber);
//				send.setPin(pin);
//				send.setTrack2Data(track2Data);
//				send.setTrack3Data(track3Data);
//				//send.setCardholderSign(cardholderSign);//电子签名
////				send.setDynamicKeyData(dynamicKeyData);
////				send.setMac(mac);
//				send.setCollectionType(tp.getPayTchannel().intValue());
//				send.setIcCardYu(icCardYu);
//				send.setCardTypeN(StringUtils.isEmpty(icCardYu) ? 1 : 2);//1 磁条卡 2 IC卡
//				send.setTransTerminalId(transTerminalId);
//				
//				AddedOrder order = new AddedOrder();
//				order.setOrderNum(orderNum);
//				order.setTerminalTypeId(terminalTypeId);
//				order.setRoleId(roleId);
//				order.setClientType(clientType);
//				order.setOrderTypeId(orderTypeId);
//				order.setUserId(userId);
//				order.setTransMoney(price);
//				order.setBankCard(accountNumber);
//				order.setMobile(mobile);
//				order.setStatus(3);
//				order.setCreateDate(date);
//				order.setLongTime(date.getTime());
//				order.setSignaturePath(signaturePath);
//				order.setChannelId(tp.getTchannel());
//				Map<String,String> thirdParamMap = new HashMap<String, String>();
//				thirdParamMap.put("faceValue", faceValue);
//				thirdParamMap.put("teltype", teltype);
//				thirdParamMap.put("chargeType", chargeType);
//				order.setThirdData(JSONStringBuilder.getAjaxString(thirdParamMap));
//				order.setPayTchannel(tp.getPayTchannel());
//				order.setCardTypeN(send.getCardTypeN());
//				order.setTransTerminalId(transTerminalId);
//				
////				//安心一百 socket 参数
////				Map<String,String> miyao = null;
////				if(tp.getPayTchannel().intValue() == 15){
////					Tchannel tc = tchannelService.searchMobileTchannelByCode(tp.getPayTchannel().intValue());
////					miyao = anxinybService.getMiYao(tc.getOtherParam());
////					send.setBankOrderNum(anxinybService.searchAnXinYBTransId().toString());//查询序列 获取动态流水号
////					send.setBatchId(miyao.get("batchId"));//批次号
////					order.setBankOrderNum(send.getBankOrderNum());
////					order.setBatchId(send.getBatchId());
////				}
////				long sendId = addedOrderService.insertOrder(send, order);
////				send.setId(sendId);
////				
////				Map<String,Object> result = new HashMap<String, Object>();
////				//去支付
////				PurchaseResult rs = null;
////				switch(tp.getPayTchannel().intValue()){
////					case 15:rs = anxinybPayService.billPayment(send, miyao.get("pinKey"), miyao.get("macKey"));break;
////					case 2:
////					case 4: rs = lianYiJiaService.fdPurchase(send);break;
////					default:rs = hanxinService.purchase(send,0.004);
////				}
//				Map<String,Object> result = new HashMap<String, Object>();
//				PurchaseResult rs = payOrder(send,order);
//				if(0 == rs.getStatus()){//
//					log.debug("支付失败");
//					resMap.clear();
//					resMap.put("reqCode", rs.getReqCode());
//					resMap.put("reqMsg", rs.getReqMsg());
//					//修改订单
//					addedOrderService.receivablesError(order.getId(),0, rs.getReqCode(), rs.getReqMsg());
//					qian4SendLogService.updateResCodeMassage(send.getId(), rs.getReqCode(), rs.getReqMsg());
//				}else{
//					order = addedOrderService.purchaseResolveResult(order,send,rs);
//					qian4SendLogService.updateResCodeMassage(send.getId(), order.getReqCode(), order.getReqMsg());
//					resMap.clear();
//					resMap.put("reqCode", order.getReqCode());
//					resMap.put("reqMsg", order.getReqMsg());
//					if("0000".equals(order.getReqCode())){
//						//String ret_url = guhua_recharge_ret_url + "?sporder_id="+orderNum+"&cardnum="+price+"&teltype="+teltype+"&chargeType"+chargeType;
//						result = ofpay.fixtelorder(orderNum, merchantOrderTime, faceValue,teltype,chargeType, mobile, guhua_recharge_ret_url);
//						log.debug("充值返回： "+result);
//						//测试数据
//	//					resMap.clear();
//						if("1".equals(result.get("reqCode")) && ("1".equals(result.get("status")) || "0".equals(result.get("status")))){
//							addedOrderService.updateThirdCodeAndMsg(order.getId(), 1, result.get("reqCode").toString(), result.get("err_msg")+"", result.get("orderid").toString());
//							resMap.put("reqCode", "0000");
//							resMap.put("reqMsg", "充值成功！");
//							//小票
//							resMap.put("category", orderType.get(order.getOrderTypeId()));
//							resMap.put("status", order.getStatus());
//							resMap.put("orderNum", order.getOrderNum());
//							resMap.put("transTime",  DateConvertUtil.dateString(order.getCreateDate(),"HH:mm:ss"));
//							String cParam = terminalTypeId+"_"+order.getId();
//							String cParamB64 = new String(Base64.encode(cParam.getBytes("UTF-8")),"UTF-8");
//							resMap.put("certificateUrl",Certificate+URLEncoder.encode(cParamB64,"UTF-8"));
//							resMap.put("merchantName", Q4BaseAction.MERCHANT_NAME);//商户名称
//							resMap.put("merchantId", Q4BaseAction.MERCHANT_ID);//商户编号
//							resMap.put("terminalId", send.getTerminalId());//终端编号
//							String acquirersName = user.getOpeningBank();
//							if(null != acquirersName){
//								acquirersName = acquirersName.replace("中国", "");
//							}
//							resMap.put("acquirersName", null != acquirersName ? acquirersName : order.getIssueBank());//收单行
//							resMap.put("issueBank", null == order.getIssueBank() ? "" : order.getIssueBank());//发卡行
//							resMap.put("bankCard", order.getBankCard());//收款卡号
//							resMap.put("cardType", null == order.getCardType()? "" : order.getCardType());//收款卡号
//							resMap.put("expireDate", null == order.getExpireDate() ? "" : order.getExpireDate());//卡有效期（预授权时）
//							resMap.put("batchId", null == order.getBatchId() ? "" : order.getBatchId());//批次号
//							resMap.put("authorizationCode", null == order.getAuthorizationCode() ? "" : order.getAuthorizationCode());//授权码
//							resMap.put("bankTransTime", DateConvertUtil.dateString(order.getCreateDate(),"yyyy/MM/dd"));//日期/时间  transPriorSettle.getBankTransTime()
//							resMap.put("transMoney", order.getTransMoney());//交易金额
//							resMap.put("bankRef", order.getBankRef());//参考号
//							resMap.put("searchId", order.getSearchId());//凭证号
//							resMap.put("transId", order.getBankOrderNum());//银联交易流水号
//							
//							resMap.put("thirdCode", null == result.get("retcode") ? "" : result.get("retcode").toString());//第三方代码
//							resMap.put("thirdMsg", null == result.get("err_msg") ? "" : result.get("err_msg"));//第三方描述
//							resMap.put("thirdOrderNum", null == result.get("orderid") ? "" : result.get("orderid"));//第三方订单号
//						}else{
//							if("1005".equals(result.get("reqCode")) || "9".equals(result.get("status"))){//只用 话费充值的撤销的情况下 我们才能撤销
//								addedOrderService.updateThirdCodeAndMsg(order.getId(), 4, result.get("retcode").toString(), result.get("err_msg")+"", null);
//								//撤销订单
//								revocationOrderTimeOut(send,order.getId());
//							}
//							resMap.clear();
//							resMap.put("reqCode", "0001");
//							resMap.put("reqMsg", "充值失败！");
//							resMap.put("thirdCode", result.get("retcode").toString());//第三方代码
//							resMap.put("thirdMsg", null == result.get("err_msg") ? "" : result.get("err_msg"));//第三方描述
//							resMap.put("thirdOrderNum", null == result.get("orderid") ? "" : result.get("orderid"));//第三方订单号
//							resMap.put("status", 4);
//						}
//					}
//				}
//				
//				//检测 银联返回结果 如果是有违法嫌疑的  那么将暂停该笔结算
//				transRefuseCardService.checkRefuseClear(userId, rs.getReqMsg(), order.getOrderNum(), order.getOrderTypeId());
//				sendAppMsg(resMap);
//			}
//		}catch(Exception e){
//			e.printStackTrace();
//			throw e;
//		}
//	}
//	
//	/**
//	 * 固话/宽带直充  与 话费充值回调雷同  为了区别代码 所有另外
//	 * http://localhost:8080/proOneMobile/ofPayRecharge/fixtelRollback.action?userid=Axxxxx&userpws=xxxxxxx&cardnum=50&teltype=1&sporder_id=xxxxxxxxx&sporder_time=xxxxxxxx&game_userid=xxxxx&md5_str=xxxxxxxxxxxxx&ret_url=xxxxx&version=6.0
//	 * mobileRollback
//	 * @throws Exception
//	 */
//	public void fixtelRollback()throws Exception{
//		log.error("固话/宽带直充回调URI：###"+getRequest().getRequestURL()+"###");
//		log.error("请求的所有参数：###"+getRequest().getParameterMap()+"###");
//		String orderNum = (String) getRequest().getParameter("sporder_id");
//		String ordersuccesstime = (String) getRequest().getParameter("ordersuccesstime");
//		Integer ret_code = Integer.parseInt((String) getRequest().getParameter("ret_code"));
//		String desc = (String) getRequest().getParameter("err_msg");
//		
//		log.debug("orderNum "+orderNum);
//		log.debug("ordersuccesstime "+ordersuccesstime);
//		log.debug("ret_code "+ret_code);
//		log.debug("err_msg "+desc);
//		
//		try{
//			AddedOrder order = new AddedOrder();
//			order.setOrderNum(orderNum);
//			order = addedOrderService.searchEntity(order);
//			Integer status = 0;
//			String resCode = "0000";
//			if(1 == ret_code){
//				status  = 1;
//			}else if(9 == ret_code){
//				status  = 4;
//			}
//			resCode = NumberUtil.supplyAll(ret_code, 4);
//			if(null != order){
//				addedOrderService.updateThirdCodeAndMsg(order.getId(), status, resCode, desc, null);
//				
//				if(9 == ret_code){//撤销
//					Qian4SendLog send = qian4SendLogService.getQian4SendLogByMOrderId(order.getOrderNum());
//					revocationOrderTimeOut(send,order.getId());
//				}
//				
//				resMap.clear();
//				resMap.put("reqCode", "0000");
//				resMap.put("reqMsg", "回调成功能！");
//				sendAjaxResponse(resMap);
//			}else{
//				resMap.clear();
//				resMap.put("reqCode", "0099");
//				resMap.put("reqMsg", "回调失败,不存在该订单！");
//				sendAjaxResponse(resMap);
//			}
//		}catch(Exception e){
//			e.printStackTrace();
//			throw e;
//		}
//	}
}
